fix(security): sanitize the user document in org-switch and /me responses - #3968
Conversation
…nses What: POST /api/organizations/:id/switch serialized the raw updatedUser straight from findByIdAndUpdatePopulated().populate() with no .select(), leaking password hash, providerData/additionalProvidersData (OAuth access+refresh tokens), reset/verification tokens, and lockout fields. GET /api/users/me separately forwarded req.user.providerData verbatim in its manually-whitelisted response. Why: a captured OAuth token or single-use reset/verification token off these responses (log pipeline, error tracker, browser history) enables account takeover; the password hash enables offline cracking. Fix: route the org-switch response through the existing UserService.removeSensitive whitelist sanitizer (same pattern already used by users.admin.controller.js and the local-signin flow) — jwt signing and ability-building still use the raw doc, only the response payload is sanitized. Drop providerData from the /me response entirely (not whitelisted, no known consumer needs it). Tests: RED-then-GREEN integration coverage for both endpoints (seeds a fake linked-OAuth token + reset token so the assertion proves the leak is actually closed, not just absent by fixture luck) plus a controller-level unit test for switchOrganization using the real sanitizeUser.removeSensitive. Closes #3963 Claude-Session: https://claude.ai/code/session_01WfNC8bt1TgL4AsiYgCEGup
|
Warning Review limit reached
Next review available in: 54 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3968 +/- ##
==========================================
+ Coverage 92.72% 93.04% +0.32%
==========================================
Files 169 169
Lines 5580 5580
Branches 1793 1793
==========================================
+ Hits 5174 5192 +18
+ Misses 326 313 -13
+ Partials 80 75 -5
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
@coderabbitai full review |
✅ Action performedFull review finished. Your plan includes PR reviews subject to rate limits. More reviews will be available in 54 minutes. |
Summary
POST /organizations/switchnow routes the responseuserthrough the existingUserService.removeSensitive()allow-list sanitizer instead of serializing the raw, unselected Mongoose document.GET /users/meno longer forwardsproviderDataverbatim in the response payload.Scope
organizations(controller),users(controller)Validation
npm run lintnpm testGuardrails check
.env*,secrets/**, keys, tokens)Notes for reviewers
password) in the actual JSON response body for both/organizations/switchand/users/me— not just presence of a sanitizer call. Full suite green (2662 tests). No secret values are restated in code, tests, or this description.https://claude.ai/code/session_01WfNC8bt1TgL4AsiYgCEGup